package com.orange.base.component.biztool.simulateddata.service.impl;

import java.util.Random;

import com.orange.base.component.biztool.simulateddata.service.SimulatedDataDao;
import com.orange.base.component.biztool.simulateddata.service.SimulatedDataDictService;
import com.orange.base.component.biztool.simulateddata.service.SimulatedDataStrategy;

public abstract class AbstractSimulatedData implements SimulatedDataStrategy {

    /**
     * 用于随机选的数字
     */
    public static final String BASE_NUMBER = "0123456789";
    /**
     * 用于随机选的字符
     */
    public static final String BASE_CHAR = "abcdefghijklmnopqrstuvwxyz";
    /**
     * 用于随机选的字符和数字
     */
    public static final String BASE_CHAR_NUMBER = BASE_CHAR + BASE_NUMBER;

    public SimulatedDataDao simulatedDataDao;

    public SimulatedDataDictService simulatedDataDictService;

    public static String randomString(int length) {
        int min = 0, max = 25;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = getRandomNumber(min, max);
            sb.append(BASE_CHAR.charAt(index));
        }
        return sb.toString();
    }

    public static String randomNumbers(int length) {
        int min = 0, max = 9;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = getRandomNumber(min, max);
            sb.append(BASE_NUMBER.charAt(index));
        }
        return sb.toString();
    }

    public static int getRandomNumber(int min, int max) {
        if (min >= max) {
            return min;
        }
        Random random = new Random();
        int randomWithMathRandom = random.nextInt(max - min) + min;
        return randomWithMathRandom;
    }

    public String getDescriptions() {
        return "";
    }

    public void setSimulatedDataDao(SimulatedDataDao simulatedDataDao) {
        this.simulatedDataDao = simulatedDataDao;
    }

    public void setSimulatedDataDictService(SimulatedDataDictService simulatedDataDictService) {
        this.simulatedDataDictService = simulatedDataDictService;
    }

    public static boolean isEmpty(Object str) {
        return (str == null || "".equals(str));
    }

    public static String toStr(Object o) {
        return o == null ? "" : o.toString();
    }

    public static int toInt(Object o) {
        return Integer.parseInt(o == null ? null : o.toString());
    }

    public static int toInt(Object o, int defaultValue) {
        return o == null || o.toString().equals("") ? defaultValue : toInt(o.toString());
    }

}
